package com.yilin.medical.views;

import com.yilin.medical.activity.HomeActivity;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class TouchStopSldingViewPager extends ViewPager {
	private HomeActivity act;
	private Handler handler;
	public TouchStopSldingViewPager(Context context) {
		super(context);
	}

	public TouchStopSldingViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	public void setTouchStopSlidingPagerAdapter(PagerAdapter adapter,Activity act,Handler handler){
		this.act = (HomeActivity)act;
		this.handler = handler;
		setAdapter(adapter);
	}
	
	
	/*@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		int action = ev.getAction();
		if (action == MotionEvent.ACTION_DOWN) {
			act.isRun = false;
			act.isDown = true;
			handler.removeCallbacksAndMessages(null);
			System.out.println("InfiniteLoopViewPager  dispatchTouchEvent =====>>> ACTION_DOWN");
		} else if (action == MotionEvent.ACTION_MOVE) {
			act.isDown = true;
			act.isRun = false;
			handler.removeCallbacksAndMessages(null);
//			System.out.println("InfiniteLoopViewPager  dispatchTouchEvent =====>>> ACTION_MOVE");
		} else if (action == MotionEvent.ACTION_UP) {
			act.isRun = true;
			act.isDown = false;
			handler.removeCallbacksAndMessages(null);
			handler.sendEmptyMessageDelayed(1, 500);
			System.out.println("InfiniteLoopViewPager  dispatchTouchEvent =====>>> ACTION_UP");
		}
		return super.dispatchTouchEvent(ev);
	}*/
	
//	
//	@Override
//	public boolean onTouchEvent(MotionEvent ev) {
//		int action = ev.getAction();
//		if (action == MotionEvent.ACTION_DOWN) {
//			act.isRun = false;
//			act.isDown = true;
//			handler.removeCallbacksAndMessages(null);
//			System.out.println("InfiniteLoopViewPager  dispatchTouchEvent =====>>> ACTION_DOWN");
//		} else if (action == MotionEvent.ACTION_MOVE) {
//			act.isDown = true;
//			act.isRun = false;
//			handler.removeCallbacksAndMessages(null);
////			System.out.println("InfiniteLoopViewPager  dispatchTouchEvent =====>>> ACTION_MOVE");
//		} else if (action == MotionEvent.ACTION_UP) {
//			act.isRun = true;
//			act.isDown = false;
//			handler.removeCallbacksAndMessages(null);
//			handler.sendEmptyMessageDelayed(1, 500);
//			System.out.println("InfiniteLoopViewPager  dispatchTouchEvent =====>>> ACTION_UP");
//		}
//		return super.onTouchEvent(ev);
//	}

}
